
	//引入express模块
	const express=require("express");
	//引入连接池模块
	const pool=require("../pool.js")
	//创建订单路由器对象
	const r=express.Router();
	//订单添加
	r.post("/order_reg",(req,res)=>{
		var $aid=req.body.aid
		var $user_id=req.body.user_id
		var $address_id=req.body.address_id
		var $stah_id=req.body.stah_id
		var sql="insert into vip_order(aid,user_id,address_id,stah_id) values(?,?,?,?)"
		pool.query(sql,[$aid,$user_id,$address_id,$stah_id],(err,result)=>{
			if(err) throw err;
			//console.log(err)
			if(result.affectedRows>0){
				res.send("1")
			}else{
				res.send("0")
			}
		})
	})
	r.get("/order_reg/check/:aid",(req,res)=>{
		var $aid=req.params.aid;
		var sql="select * from vip_order where aid=?"
		pool.query(sql,[$aid],(err,result)=>{
			if(err){
				throw err
			}
			if(result.length>0){
				res.send("1")
			}else{
				res.send("0")
			}
		})
		
	})
	//订单搜索
	r.get("/order_search/:aid",(req,res)=>{
		var $aid=req.params.aid;
		var sql="select * from vip_order where aid=?"
		pool.query(sql,[$aid],(err,result)=>{
			if(err){
				throw err
			}
			if(result.length>0){
				res.send(result)
			}else{
				res.send("0")
			}
		})
		
	})

	//订单修改
	r.put("/order_revise",(req,res)=>{
		var obj=req.body;
		//console.log(obj);
		var sql="update vip_order set? where aid=?"
		pool.query(sql,[obj,obj.aid],(err,result)=>{
			if(err) throw err;
			if(result.affectedRows>0){
				res.send("1")
			}else{
				res.send("0")
			}
		})
	})

	//订单删除
	r.delete("/order_del/:aid",(req,res)=>{
		var $aid=req.params.aid;
		// console.log($aid);
		var sql="delete from vip_order where aid=?"
		pool.query(sql,[$aid],(err,result)=>{
			if(err) throw err;		
			if(result.affectedRows>0){			
				res.send("1")
			}else{
				res.send("0")
			}
		})
	})

	//导出订单路由器对象
	module.exports=r;
